﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SASystem
{
    public partial class DownLoadFrm : Form
    {
        private string m_fileName;
        private string m_finalPath;
        public DownLoadFrm(string fileName)
        {
            InitializeComponent();
            m_fileName = fileName;
        }

        private void button_ok_Click(object sender, EventArgs e)
        {
            if (this.CheckInput())
            {
                m_finalPath = System.IO.Path.Combine(this.textBox_path.Text, String.Format("{0}.{1}", this.textBox_filename.Text, this.comboBox_filetype.Text.ToLower()));
            }

            SABLL.SetConfig(ConfigKeys.DownloadFolder, this.textBox_path.Text);
        }

        public string GetFilePath()
        {
            return m_finalPath;
        }

        private bool CheckInput()
        {
            if (String.IsNullOrEmpty(this.textBox_path.Text))
            {
                SABLL.ShowInfoMsg(@"保存路径不能为空！");
                return false;
            }

            if (String.IsNullOrEmpty(this.textBox_filename.Text))
            {
                SABLL.ShowInfoMsg(@"文件名不能为空！");
                return false;
            }

            return true;
        }

        private void DownLoadFrm_Load(object sender, EventArgs e)
        {
            SABLL.InitFileTypeComboBoxView(this.comboBox_filetype);

            this.textBox_path.Text = SABLL.GetConfig(ConfigKeys.DownloadFolder);

            this.textBox_filename.Text = m_fileName;
        }

        private void button_path_Click(object sender, EventArgs e)
        {
            string folder = SABLL.OpenFolderBrowser();
            this.textBox_path.Text = folder;
        }

    }
}
